﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using System;
using ServerBase.Other;
using System.Linq;
using ServerPublic.Manager;
using ServerGame.GameObject;
using static ServerGame.Service.Dispatcher;
using System.Diagnostics;
using ServerPublic.DataBaseMysql;
using ServerPublic.Data;
using ServerGame.Data;
using ServerBase.LunarSocket;

namespace ServerGame.Manager
{
    /// <summary>
    /// 信息管理器
    /// </summary>
    public static class InfoMgr
    {

        #region 信息
        
        // 获取基本信息
        public static CLS_Info_Base GetInfoBase(this Player player)
        {
            var result = new CLS_Info_Base()
            {
                Puid = player.Uid,

                Name = player.Name,
                Gender = player.Gender,
                Family = player.Family,
                Title = player.Title,
                Age = player.Age,

                Level = player.DaCommon.Level,
                Exp = player.DaCommon.Exp,

                Gem = player.DaBasic.Gem,
                Gold = player.DaBasic.Gold,
                Pot = player.DaBasic.Pot,

                VipLevel = player.DaBasic.VipLevel,
                VipExp = player.DaBasic.VipExp,

            };
            return result;
        }
        // 获取杂项信息
        public static CLS_Info_Misc GetInfoMisc(this Player player)
        {
            var info = new CLS_Info_Misc()
            {
                ServerConfigId = BaseServerInfo.ConfigId,
                ServerTime = DateTime.Now,
                ServerTimeOpen = BaseServerInfo.ServerTimeOpen,
                DictFlagClient = player.DaMisc.DictFlagClient,
                DictFlagClientDaily = player.DaMisc.DictFlagClientDaily,
            };

            info.DtRegister = new DateTime(player.DaMisc.TicksRegister);

            GetInfoMiscFlag(player, ref info);

            return info;
        }
        // 获取游戏信息
        public static CLS_Info_Game GetInfoGame(this Player player)
        {
            var info = new CLS_Info_Game()
            {
            };
            return info;
        }
        // 获取属性信息
        public static void GetInfoProp(this Player player, ref Dictionary<int, int> info)
        {
            for (int prop = (int)EProp.kee; prop <= (int)EProp.mxwater; prop++)
            {
                info[prop] = player[(EProp)prop];
            }
        }
        // 获取属性信息
        public static void GetInfoProp(this Player player, ref CLS_Info_Prop info)
        {
            info.str = player[EProp.str];
            info.itn = player[EProp.itn];
            info.con = player[EProp.con];
            info.spi = player[EProp.spi];
            info.cps = player[EProp.cps];
            info.cor = player[EProp.cor];
            info.per = player[EProp.per];
            info.kar = player[EProp.kar];

            info.kee = player[EProp.kee];
            info.sen = player[EProp.sen];
            info.force = player[EProp.force];
            info.mana = player[EProp.mana];
            info.food = player[EProp.food];
            info.water = player[EProp.water];

            info.efkee = player[EProp.efkee];
            info.efsen = player[EProp.efsen];
            info.mxkee = player[EProp.mxkee];
            info.mxsen = player[EProp.mxsen];
            info.mxforce = player[EProp.mxforce];
            info.mxmana = player[EProp.mxmana];
            info.mxfood = player[EProp.mxfood];
            info.mxwater = player[EProp.mxwater];

            info.adstr = player[EProp.adstr];
            info.aditn = player[EProp.aditn];
            info.adcon = player[EProp.adcon];
            info.adspi = player[EProp.adspi];
            info.adcps = player[EProp.adcps];
            info.adcor = player[EProp.adcor];
            info.adper = player[EProp.adper];
            info.adkar = player[EProp.adkar];

            info.adkee = player[EProp.adkee];
            info.adsen = player[EProp.adsen];
            info.adforce = player[EProp.adforce];
            info.admana = player[EProp.admana];
            info.adfood = player[EProp.adfood];
            info.adwater = player[EProp.adwater];

            info.damage = player[EProp.damage];
            info.armor = player[EProp.armor];
            info.cattack = player[EProp.cattack];
            info.cdefence = player[EProp.cdefence];
            info.cdodge = player[EProp.cdodge];
            info.cparry = player[EProp.cparry];
            info.cforce = player[EProp.cforce];
            info.cspell = player[EProp.cspell];

            info.cbtdamage = player[EPropCbt.damage];
            info.cbtarmor = player[EPropCbt.armor];
            info.cbtattack = player[EPropCbt.attack];
            info.cbtdefence = player[EPropCbt.defence];
            info.cbtdodge = player[EPropCbt.dodge];
            info.cbtparry = player[EPropCbt.parry];
            info.cbtforce = player[EPropCbt.force];
            info.cbtspell = player[EPropCbt.spell];

        }
        // 获取杂项信息
        public static void GetInfoMiscFlag(Player player, ref CLS_Info_Misc info)
        {
            info[EFlagInt.未读邮件数目] = player.DaMail.SortDictMails.Values.Count(it => !it.Readed);

        }
        // 获取玩家信息
        public static CLS_Info_Player GetInfoPlayer(this Player player)
        {
            var result = new CLS_Info_Player()
            {
                Puid = player.Uid,
                Name = player.Name,
                Gender = player.Gender,
                Family = player.Family,

            };
            result.IsOnline = player.IsOnline;

            return result;
        }
        // 所有玩家推送
        public static void BoardcastInfoAll()
        {
            foreach (var player in DataGame.DictPlayerOnline.Values)
            {
                player.InfoAll();
            }
        }
        // 推送玩家信息 全部
        public static void InfoAll(this Player player)
        {
            if (!player.IsOnline)
            {
                return;
            }
            var Rsp = new G2C_Info_PushAll()
            {
                InfoBase = GetInfoBase(player),
                InfoMisc = GetInfoMisc(player),
                InfoGame = GetInfoGame(player),
            };
            player.GetInfoProp(ref Rsp.InfoProp);
            player.GetInfoProp(ref Rsp.DictProp);
            player.Send(Rsp);
        }
        // 推送玩家信息 基础
        public static void InfoBase(this Player player)
        {
            if (!player.IsOnline)
            {
                return;
            }
            var Rsp = new G2C_Info_PushBase()
            {
                InfoBase = GetInfoBase(player),
                InfoMisc = GetInfoMisc(player),
            };
            player.GetInfoProp(ref Rsp.InfoProp);
            player.GetInfoProp(ref Rsp.DictProp);
            player.Send(Rsp);
        }
        

        #endregion



        


    }
}